home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / µSim 1.0.5 / source / Animation.c < prev    next >
Encoding:
Text File  |  1995-10-24  |  7.8 KB  |  300 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994,1995 Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware:
  5. you may copy, exchange, modify this code.
  6. You may include this code in any kind of application: freeware,
  7. shareware, or commercial, provided that full credits are given.
  8. You may not sell or distribute this code for profit.
  9. */
  10.  
  11. //#pragma load "MacDump"
  12.  
  13. #include    "UtilsSys7.h"
  14. #include    "Conversions.h"
  15.  
  16. #include    "Globals.h"
  17. #include    "Animation.h"
  18. #include    "ControlStore.h"
  19. #include    "DoEditDialog.h"
  20. #include    "DoMenu.h"
  21. #include    "Main.h"
  22. #include    "Registers.h"
  23.  
  24. #if defined(FabSystem7orlater)
  25.  
  26. //#pragma segment Main
  27.  
  28. GrafPtr    offScr;        /* offscreen GrafPort for animation */
  29. PicHandle    images[kLAST_PICT - kFIRST_PICT + 1];    /* Handles to Pictures */
  30. Rect    rval[kP_MIR - kP_ALATCH + kMIRSubboxes];    /* in these rects we write the values */
  31. RgnHandle    mirUpdRgn;
  32.  
  33. static Boolean PtInObj(Point, RectPtr, short obj);
  34.  
  35. /* PtInObj: finds out if thePt is in the obj object, returning the object
  36. Rect in neededRect */
  37.  
  38. static Boolean PtInObj(Point thePt, RectPtr neededRect, short obj)
  39. {
  40. register PicHandle    tempPH;
  41.  
  42. tempPH = images[obj];
  43. if (*tempPH == nil)
  44.     LoadResource((Handle)tempPH);
  45. *neededRect = (*tempPH)->picFrame;
  46. neededRect->right--;
  47. neededRect->bottom--;
  48. return(PtInRect(thePt, neededRect));
  49. }
  50.  
  51. /* UpdateMir: takes care of updating the mir image in the Animation window */
  52.  
  53. void UpdateMir(un_mir newmir)
  54. {
  55. Str255    tempS;
  56. GrafPtr    savePort;
  57. register RectPtr    RectScan = &rval[kP_MIR - kP_ALATCH];
  58.  
  59. GetPort(&savePort);
  60. SetPort(offScr);
  61. MyNumToString((newmir).bits.amux, tempS);
  62. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  63. MyNumToString((newmir).bits.cond, tempS);
  64. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  65. MyNumToString((newmir).bits.alu, tempS);
  66. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  67. MyNumToString((newmir).bits.shift, tempS);
  68. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  69. MyNumToString((newmir).bits.mbr, tempS);
  70. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  71. MyNumToString((newmir).bits.rd, tempS);
  72. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  73. MyNumToString((newmir).bits.wr, tempS);
  74. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  75. MyNumToString((newmir).bits.mar, tempS);
  76. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  77. MyNumToString((newmir).bits.dsc, tempS);
  78. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  79. ShortToHexString((newmir).bits.a, tempS);
  80. TETextBox(&tempS[4], 1, RectScan++, teJustCenter);
  81. ShortToHexString((newmir).bits.b, tempS);
  82. TETextBox(&tempS[4], 1, RectScan++, teJustCenter);
  83. ShortToHexString((newmir).bits.c, tempS);
  84. TETextBox(&tempS[4], 1, RectScan++, teJustCenter);
  85. MyNumToString((newmir).bits.map, tempS);
  86. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
  87. MyNumToString((newmir).bits.addr, tempS);
  88. TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustRight);
  89. SetPort(gWPtr_Animation);
  90. InvalRgn(mirUpdRgn);
  91. SetPort(savePort);
  92. }
  93.  
  94. /* ChangedBox: does all the housekeeping when an on-screen object is modified */
  95.  
  96. void ChangedBox(int obj)
  97. {
  98. Str255    tempS;
  99. GrafPtr    savePort;
  100.  
  101. GetPort(&savePort);
  102. SetPort(offScr);
  103. ShortToHexString(gParts[obj], tempS);
  104. if((obj >= kP_INCR - kFIRST_PICT)&&(obj <= kP_MPC - kFIRST_PICT)) {
  105.     *(Byte *)(&gParts[obj]) = 0;
  106.     MyNumToString(gParts[obj], tempS);
  107.     }
  108. else {
  109.     if( obj == kP_ALU - kFIRST_PICT ) {
  110.         register unsigned char *mslstring = (unsigned char *)&tempS + 8;
  111.         register StringPtr ZeroandOne = *GetString(kSTR_BINALLOWED);
  112.  
  113.         *mslstring++ = (gParts[kP_ALU - kFIRST_PICT] < 0 ? *(ZeroandOne+2) : *(ZeroandOne+1));
  114.         *mslstring++ = 13;
  115.         *mslstring++ = (gParts[kP_ALU - kFIRST_PICT] == 0 ? *(ZeroandOne+2) : *(ZeroandOne+1));
  116.         TextSize(9);
  117.         TETextBox((unsigned char *)&tempS + 8, 3, &rval[kP_MSL - kFIRST_PICT], teJustCenter);
  118.         TextSize(12);
  119.         }
  120.     }
  121. TETextBox(&tempS[1], StrLength(tempS), &rval[obj], teJustCenter);
  122. SetPort(gWPtr_Animation);
  123. InvalRect(&rval[obj]);
  124. if (obj == kP_ALU - kFIRST_PICT)
  125.     InvalRect(&rval[kP_MSL - kFIRST_PICT]);
  126. SetPort(savePort);
  127. }
  128.  
  129. void ChangedAllBoxes(void)
  130. {
  131. register int    i;
  132.  
  133. for (i = kP_ALATCH - kFIRST_PICT; i <= kP_ALU - kFIRST_PICT; ChangedBox(i++))
  134.     ;
  135. }
  136.  
  137. /* ActivateObjs: activates (blackens) a list of objects */
  138.  
  139. void ActivateObjs(const short *objs)
  140. {
  141. Rect    tempRect;
  142. GrafPtr    savePort;
  143. short    pos;
  144.  
  145. GetPort(&savePort);
  146. SetPort(offScr);
  147. PenNormal();
  148.  
  149. for( ; pos = *objs++; ) {
  150.     register PicHandle    tempPicH;
  151.     
  152.     tempPicH = images[pos - kFIRST_PICT];
  153.     if( *tempPicH == nil ) /* Resource purged */
  154.         LoadResource((Handle)tempPicH);
  155.     tempRect = (*tempPicH)->picFrame;
  156.     SetPort(offScr);
  157.     DrawPicture(tempPicH, &tempRect);
  158.     SetPort(gWPtr_Animation);
  159.     InvalRect(&tempRect);
  160.     }
  161. SetPort(savePort);
  162. }
  163.  
  164. /* DeactivateObjs: deactivates (grays) a list of objects */
  165.  
  166. void DeactivateObjs(const short *objs)
  167. {
  168. Rect    tempRect;
  169. GrafPtr    savePort;
  170. register RgnHandle    tempRgn = NewRgn();
  171. register RgnHandle    tempRgn2 = NewRgn();
  172. register short    pos;
  173.  
  174. GetPort(&savePort);
  175. SetPort(offScr);
  176. PenPat(&qd.gray);
  177. PenMode(notPatBic);
  178.  
  179. for( ; pos = *objs++; ) {
  180.     register PicHandle    tempPicH;
  181.     
  182.     tempPicH = images[pos - kFIRST_PICT];
  183.     if( *tempPicH == nil ) /* Resource purged */
  184.         LoadResource((Handle)tempPicH);
  185.     tempRect = (*tempPicH)->picFrame;
  186.     SetPort(offScr);
  187.     DrawPicture(tempPicH, &tempRect);
  188.     tempRect.right--;
  189.     tempRect.bottom--;
  190.     if(pos <= kP_MIR) {
  191.         if(pos == kP_MIR) {
  192.             CopyRgn(mirUpdRgn, tempRgn2);
  193.             InvertRgn(mirUpdRgn);
  194.             }
  195.         else
  196.             RectRgn(tempRgn2, &rval[pos - kP_ALATCH]);
  197.         RectRgn(tempRgn, &tempRect);
  198.         DiffRgn(tempRgn, tempRgn2, tempRgn);
  199.         }
  200.     else
  201.         RectRgn(tempRgn, &tempRect);
  202.     PaintRgn(tempRgn);
  203.     SetPort(gWPtr_Animation);
  204.     InvalRect(&tempRect);
  205.     }
  206. DisposeRgn(tempRgn2);
  207. DisposeRgn(tempRgn);
  208. SetPort(savePort);
  209. }
  210.  
  211. /* Update_Animation: handler for the update event */
  212.  
  213. void Update_Animation(WindowPtr w)
  214. {
  215. //Str15    tempS;
  216.  
  217. CopyBits(&offScr->portBits, &w->portBits, &offScr->portBits.bounds,
  218.             &w->portRect, srcCopy, nil);
  219.  
  220. /*
  221. MyNumToString(timingInfo, tempS);
  222. MoveTo(40,40);
  223. DrawString(&tempS);
  224. */
  225. }
  226.  
  227. /* Do_Animation: someone has clicked in content … */
  228.  
  229. void Do_Animation(WindowPtr /*w*/, EventRecord *theEvent)
  230. {
  231. //#pragma unused (w)
  232.  
  233. Rect    tempRect;
  234. Point    myPt;
  235. register short    code;
  236.  
  237. myPt = theEvent->where;
  238. GlobalToLocal(&myPt);
  239. if (PtInObj(myPt, &tempRect, code = kP_ALATCH - kFIRST_PICT) ||
  240.     PtInObj(myPt, &tempRect, code = kP_BLATCH - kFIRST_PICT) ||
  241.     PtInObj(myPt, &tempRect, code = kP_MAR - kFIRST_PICT) ||
  242.     PtInObj(myPt, &tempRect, code = kP_MBR - kFIRST_PICT) ||
  243.     PtInObj(myPt, &tempRect, code = kP_AMUX - kFIRST_PICT) ||
  244.     PtInObj(myPt, &tempRect, code = kP_ALU - kFIRST_PICT) ||
  245.     PtInObj(myPt, &tempRect, code = kP_SHIFTER - kFIRST_PICT) ||
  246.     PtInObj(myPt, &tempRect, code = kP_MMUX - kFIRST_PICT) ||
  247.     PtInObj(myPt, &tempRect, code = kP_INCR - kFIRST_PICT) ||
  248.     PtInObj(myPt, &tempRect, code = kP_MPC - kFIRST_PICT) ||
  249.     PtInObj(myPt, &tempRect, code = kP_REGISTERS - kFIRST_PICT) ||
  250.     (PtInObj(myPt, &tempRect, code = kP_CONTSTORE - kFIRST_PICT) && DocIsOpen) ) {
  251.     if (TrackObject(&tempRect)) {
  252.         if (code == kP_REGISTERS - kFIRST_PICT)
  253.             DoMenuWindows(kMItem_Registers);
  254.         else if (code == kP_CONTSTORE - kFIRST_PICT)
  255.             DoMenuWindows(kMItem_Microprogram);
  256.         else {
  257.             (void)DoEditDialog(code, kPART_NAMES,
  258.                                 (code >= kP_INCR - kFIRST_PICT) &&
  259.                                     (code <= kP_MPC - kFIRST_PICT) ? kPOP_DEC : kPOP_HEX);
  260.             UnloadSeg(DoEditDialog);
  261.             }
  262.         }
  263.     }
  264. }
  265.  
  266. /* TrackObject: like all the TrackThing in the Mac OS */
  267.  
  268. Boolean    TrackObject(RectPtr    r)
  269. {
  270. Point    myPt;
  271. register Boolean    inrect;
  272.  
  273. InvertRect(r);
  274. inrect = true;
  275. do {
  276.     register Boolean tempB;
  277.  
  278.     GetMouse(&myPt);
  279.     if ((tempB = PtInRect(myPt, r)) != inrect) {
  280.         InvertRect(r);
  281.         inrect = tempB;
  282.         }
  283.     }
  284. while( StillDown() );
  285. if (inrect) {
  286.     InvertRect(r);
  287.     }
  288. return inrect;
  289. }
  290.  
  291. /* procedure called when closing the Animation window */
  292.  
  293. void CloseAnimation(WindowPtr w)
  294. {
  295. DoCloseWindow(w, kMItem_Animation);
  296. }
  297.  
  298. #endif
  299.  
  300.